
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<span style="font-size:18px;">
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="attendance/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="attendance/css/commonly-used-show.css" />
    <script type="text/javascript" src="attendance/js/jquery.min.js"></script>
    <script type="text/javascript" src="attendance/js/bootstrap.js" ></script>

    <link rel="stylesheet" type="text/css" href="attendance/css/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="attendance/css/modal.css" />
    <script type="text/javascript" src="attendance/js/modal.js" ></script>

    <title>考勤管理</title>

    <style type="text/css">
        td, th {
            text-align: center;
        }
    </style>
</head>

<body class="mybody">


<jsp:include page="theTopMenuTeacher.jsp" />


<div class="container-fluid">
    <div class="row">

        <div class="col-md-12">
            <div class="col-md-12">
                    <div class="panel panel-primary">
                        <div class="panel-body">

                            <div>
    <h3 style="text-align: center">我的考勤信息</h3>
    <table border="1" class="table table-bordered table-hover">
        <thead>
        <tr class="success">
            <th>序号</th>
            <th>年级</th>
            <th>学院</th>
            <th>班级</th>
            <th>课程名称</th>
            <th>打卡星期</th>
            <th>上课打卡时间</th>
            <th>下课打卡时间</th>
            <th>创建时间</th>
            <th>操作</th>
        </tr>
        </thead>

        <tbody id="tbody-result">
        </tbody>

        <tr><td style="border-style: none;">&nbsp&nbsp;</td></tr>
        <tr>
            <td colspan="10" align="center"><a class="btn btn-primary" href="${pageContext.request.contextPath}/attendanceSetting">添加考勤规则</a></td>
        </tr>
    </table>

                                <div class="text-center">
            <label id="user_null" style="color: red"></label>
        </div>
</div>

                        </div>
                    </div>
                </div>
        </div>



    </div>

 </div>


<script type="text/javascript">
    var userdt = JSON.parse(sessionStorage.getItem("user"));
    var thcoursely = JSON.parse(sessionStorage.getItem("thcourse"));
    var userNull = document.getElementById("user_null");
    if (userdt.result.userName != null){
        $("#usname").text(userdt.result.userName);
    }else {
        $("#usname").text(userdt.result.userLoginName);
    }


    window.onload = function(){
        attendanceInfo();
    }

    function attendanceInfo(){
        var postUrl = "${pageContext.request.contextPath}/member/queryUserAttendanceInformation";

        var str = {
            "userId": userdt.result.id,
            "courseTitle": thcoursely.result.courseTitle,
        };

        $.ajax({
            type:"post",
            url:postUrl,
            headers: {
                "Content-Type":"application/json"
            },
            data:JSON.stringify(str),
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            success:function(data){
                if (data.status == "0"){
                    userNull.innerHTML = data.msg;
                }else {
                    var strtab = "";
                    //清空表格数据
                    $("#tbody-result").html("");

                    var conter = 1;
                    for (var i = 0; i < data.result.length; i++) {

                        strtab = "<tr>" + "<td>" + conter + "</td>"
                            + "<td>" + data.result[i].grade + "</td>"
                            + "<td>" + data.result[i].college + "</td>"
                            + "<td>" + data.result[i].classAndGrade + "</td>"
                            + "<td>" + data.result[i].courseTitle + "</td>"
                            + "<td>" + data.result[i].attendDate + "</td>"
                            + "<td>" + data.result[i].startAttendTime + "</td>"
                            + "<td>" + data.result[i].endAttendTime + "</td>"
                            + "<td>" + data.result[i].createTime + "</td>"
                            + "<td>" + "<a class=\"btn btn-default btn-sm\" href=${pageContext.request.contextPath}/updateAttendanceSetting?id=" + data.result[i].id + ">修改 </a> "
                            + " <a class=\"btn btn-default btn-sm\" href=\"#\" onclick=\"deletClockRulesse(' " + data.result[i].id + "')\">删除</a>" + "</td>"
                            + "</tr>";
                        $("#tbody-result").append(strtab);//将数据追加进表格

                        conter++;
                    }
                }

            },
            error:function(xhr,state,errorThrown){
                //alert("发生网络错误，错误码为：" + xhr.status)
                location.href = "${pageContext.request.contextPath}/error";
            }
        });
    }


    function deletClockRulesse(datees){
        var mModal2 = new mModal({
            top: "40vh",
            content: "你确定要删除此项？",
            confirm: function () {
                deletClockRulesse1(datees);
                mModal2.close();
            },
            cancel: function () {
            }
        });

        mModal2.renderDom();

    }

    function deletClockRulesse1(id){
        var postUrl = "${pageContext.request.contextPath}/member/deletClockRulesse";
        var str = {
            "id": id
        };

        $.ajax({
            type:"post",
            url:postUrl,
            headers: {
                "Content-Type":"application/json"
            },
            data:JSON.stringify(str),
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            success:function(data){
                if (data.status == "0"){
                    alert(data.msg)
                }else {
                    location.reload();
                }
            },
            error:function(xhr,state,errorThrown){
                //alert("发生网络错误，错误码为：" + xhr.status)
                location.href = "${pageContext.request.contextPath}/error";
            }
        });
    }
</script>

</body>
</html>
</span>